﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using OpenQA.Selenium;
using OpenQA.Selenium.Chrome;
using OpenQA.Selenium.Firefox;
using OpenQA.Selenium.IE;
using OpenQA.Selenium.PhantomJS;

namespace Fluent
{
    public static class BrowserLoader
    {
        public static Browser Load(EBrowserType browserType, bool maxWindow)
        {
            IWebDriver driver;
            switch (browserType)
            {
                case EBrowserType.IE:
                    driver = new InternetExplorerDriver();
                    break;
                case EBrowserType.Chrome:
                    ChromeOptions chromeOptions = new ChromeOptions();
                    if (maxWindow)
                    {
                        chromeOptions.AddArguments("start-maximized");
                    }

                    driver = new ChromeDriver(chromeOptions);
                    break;
                case EBrowserType.Firefox:
                    driver = new FirefoxDriver();
                    break;
                case EBrowserType.PhantomJS:
                    driver = new PhantomJSDriver();
                    break;
                default:
                    throw new NotSupportedException("Not support browser type!");
            }

            if (maxWindow && browserType != EBrowserType.Chrome)
            {
                driver.Manage().Window.Maximize();
            }

            return new Browser(driver, browserType);
        }

        public static void Unload(Browser browser)
        {
            browser.Quit();
        }
    }
}
